<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>百度示例</title>
    <link rel="stylesheet" href="css/ol.css" type="text/css">
    <link rel="stylesheet" href="css/gis.css" type="text/css">
    <script src="js/ol-debug.js"></script>

</head>

<body>
<div id="map">
    <div id="popup" class="ol-popup">
        <a href="#" id="popup-closer" class="ol-popup-closer"></a>
        <div id="popup-content"></div>
    </div>
    <div id="wrapper">
        <div id="location"></div>
        <div id="scale"></div>
    </div>
</div>
</body>
<script type="text/javascript">
    var projection = ol.proj.get("EPSG:3857");
    var resolutions = [];
    for (var i = 0; i < 19; i++) {
        resolutions[i] = Math.pow(2, 18 - i);
    }
    var tilegrid = new ol.tilegrid.TileGrid({
        origin: [0, 0],
        resolutions: resolutions
    });
    var baidu_source = new ol.source.TileImage({
        projection: projection,
        tileGrid: tilegrid,
        wrapX: true,
        tileUrlFunction: function (tileCoord, pixelRatio, proj) {
            if (!tileCoord) {
                return "";
            }
            var z = tileCoord[0];
            var x = tileCoord[1];
            var y = tileCoord[2];
            if (x < 0) {
                x = "M" + (-x);
            }
            if (y < 0) {
                y = "M" + (-y);
            }
            return "http://online3.map.bdimg.com/onlinelabel/?qt=tile&x=" + x + "&y=" + y + "&z=" + z + "&styles=pl&udt=20151021&scaler=1&p=1";
        }
    });
    var baidu_layer = new ol.layer.Tile({
        source: baidu_source,
    });
    var map = new ol.Map({
        target: 'map',
        layers: [baidu_layer],
        view: new ol.View({
            center: [12959773, 4853101],
            zoom: 8,
            extent: [-20037508.3427892 / 1.9, -20037508.3427892 / 1.9, 20037508.3427892 / 1.9, 20037508.3427892 / 1.9]
        }),
        controls: ol.control
            .defaults({
                zoom: false,
                rotate: false,
                attribution: false,
            }).extend([new ol.control.PanZoomBar({'position':new ol.pixel(50, 0), 'zoomStopHeight':5})]),

    });
    console.log(map.getSize())
</script>

</html>